package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import org.apache.hbase.thirdparty.io.netty.util.internal.StringUtil;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

@Component
public class ArticleIsDownListener {

    @Resource
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message) {

        if (!StringUtil.isNullOrEmpty(message)) {
            HashMap hashMap = JSON.parseObject(message, HashMap.class);
            apArticleConfigService.updateByMap(hashMap);
        }
    }
}
